package top.drinyeit.weilong.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.app.Constant;
import top.drinyeit.weilong.base.BaseActivity;
import top.drinyeit.weilong.presenter.NickNamePresenter;
import top.drinyeit.weilong.util.SPUtil;

/**
 * Created by bigHead on 2017/11/20.
 */

public class NickNameActivity extends BaseActivity {

    private ImageView delete_all;//删除按钮
    public TextView nick_name, save_btn;//昵称

    public String headPic, nickName;
    public int sexNo;

    private NickNamePresenter nickNamePresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_nickname);

        initView();
        initIntent();
        init();
        setTitle(true, "修改昵称");
    }

    private void initView() {
        delete_all = findViewById(R.id.delete_all);
        nick_name = findViewById(R.id.nick_name);
        save_btn = findViewById(R.id.save_btn);
    }

    private void initIntent() {
        Bundle bundle = getIntent().getExtras();
        nickName = bundle.getString("nick_name");
        nick_name.setText(nickName);
        nick_name.setSelectAllOnFocus(true);
    }

    @Override
    public void init() {
        nickNamePresenter = new NickNamePresenter(this);
        delete_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                nick_name.setText("");
            }
        });
        //保存
        save_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (nick_name.getText().length() < 1) {
                    showToast("昵称不能为空");
                    return;
                }
                Map<String, Object> map = new HashMap<>();
                map.put("action", "user_edit_info");
                map.put("user_id", SPUtil.getShareString(Constant.USER_ID));
                map.put("nick_name", nick_name.getText().toString());
                nickNamePresenter.editInf(map);
            }
        });
    }
}
